********************************************************************************		
************************* Benchmark regressions ********************************
********************************************************************************
clear
use "BHPS_merged.dta"

do "ML programs to add model statistics.do"
	
	
********** Multilevel models for growth rate measure of China shock ********
	* global with individual-level control variables
	global controls "i.education i.male c.age_cent##c.age_cent i.bornelsewhere2 i.parentsbornelsewhere"

	
*** EU support
	global tradevar "real_gr_imp_CH_d_eu_nl"		

	* without controls
	mixed D_EUsupport c.LDV_EUsupport##i.year ///
		$tradevar ///
		$controls i.ID_NUTS1xYear ///
		if (year==2006 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: , stddeviations 

		add_scalars_mixed_2level
		sum D_EUsupport $tradevar if e(sample)
														
		eststo EU1	

	* with controls: employment share				
	mixed D_EUsupport c.LDV_EUsupport##i.year ///
		$tradevar ///
		emplsh_manufact_1998 ///
		$controls i.ID_NUTS1xYear ///
		if (year==2006 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: , stddeviations 

		add_scalars_mixed_2level
		sum D_EUsupport $tradevar if e(sample)
		
		eststo EU2	

	* with all controls				
	mixed D_EUsupport c.LDV_EUsupport##i.year ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_eu ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2006 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations

		add_scalars_mixed_3level						
		sum D_EUsupport $tradevar if e(sample)
								
				capture drop pickone
				egen pickone=tag(ID_NUTS3xYear) if e(sample)
				_pctile real_gr_imp_CH_d_eu if pickone==1, p(23)
				ret li
				
				_pctile real_gr_imp_CH_d_eu if pickone==1, p(89)
				ret li
					
				sort real_gr_imp_CH_d_eu
				list nuts3_2006_name year real_gr_imp_CH_d_eu if pickone==1 & year==2006
				
				sort pid waven		
					
		eststo EU3	
	
	* with all controls & NUTS2-year FE						
	mixed D_EUsupport c.LDV_EUsupport##i.year ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_eu ///
		$controls i.ID_NUTS2xYear  ///
		if (year==2006 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations

		add_scalars_mixed_3level
		sum D_EUsupport $tradevar if e(sample)
		
		eststo EU4				

	* write table
	esttab EU1 EU2 EU3 EU4 using "ML regressions benchmark_EU support.rtf", b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
		scalars(group1N group2N group3N ri1_std ri2_std ri3_std icc1 icc2 icc3 bic) varwidth(30) nogaps compress ///
		drop(0.male 0.education 0.bornelsewhere2 0.parentsbornelsewhere 2002.year *.ID_NUTS1xYear *.ID_NUTS2xYear lnsig_e:_cons) ///
		label replace transform(ln*: exp(@) exp(@)) 	
		
					
*** Nationalism
	global tradevar "real_gr_imp_CH_d3_nl"

	* without controls
	mixed D3_nationalism L3.nationalism ///
		$tradevar ///
		$controls i.ID_NUTS1xYear ///
		if (year==2008 | year==2005 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: , stddeviations 

		add_scalars_mixed_2level
		sum D3_nationalism $tradevar if e(sample)				
		
		eststo NAT1	

	* with controls: employment share				
	mixed D3_nationalism L3.nationalism ///
		$tradevar ///
		emplsh_manufact_1998 ///
		$controls i.ID_NUTS1xYear ///
		if (year==2008 | year==2005 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: , stddeviations 
		
		add_scalars_mixed_2level
		sum D3_nationalism $tradevar if e(sample)				

		eststo NAT2	

	* with all controls				
	mixed D3_nationalism L3.nationalism ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_nat ///
		$controls i.ID_NUTS1xYear  ///
		if (year==2008 | year==2005 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations 

		add_scalars_mixed_3level
		sum D3_nationalism $tradevar if e(sample)				

				capture drop pickone
				egen pickone=tag(ID_NUTS3xYear) if e(sample)
				_pctile real_gr_imp_CH_d3 if pickone==1, p(30)
				ret li
				
				_pctile real_gr_imp_CH_d3 if pickone==1, p(95)
				ret li
					
				sort real_gr_imp_CH_d3
				list nuts3_2006_name year real_gr_imp_CH_d3 if pickone==1 & year==2005
				
				sort pid waven		
						
		eststo NAT3	

	* with all controls & NUTS2-year FE						
	mixed D3_nationalism L3.nationalism  ///
		$tradevar ///
		emplsh_manufact_1998 pop_sharenonUK pop_sharenonUK_d_nat ///
		$controls i.ID_NUTS2xYear   ///
		if (year==2008 | year==2005 | year==2002) ///
		|| ID_NUTS3: || ID_NUTS3xYear: || ID_lad13xyear: , stddeviations
		
		add_scalars_mixed_3level
		sum D3_nationalism $tradevar if e(sample)				

		eststo NAT4			
					
	* write table
	esttab NAT1 NAT2 NAT3 NAT4 using "ML regressions benchmark_Nationalism.rtf", b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
		scalars(group1N group2N group3N ri1_std ri2_std ri3_std icc1 icc2 icc3 bic) varwidth(30) nogaps compress ///
		drop(0.male 0.education 0.bornelsewhere2 0.parentsbornelsewhere *.ID_NUTS1xYear *.ID_NUTS2xYear lnsig_e:_cons) /// 
		label replace transform(ln*: exp(@) exp(@)) 